// #include "bsp_tim.h"
#include "at32f403a_407.h"
#include "cbb_init.h"
#include "cbb_event.h"

Event_t* pstEventTim6;

void bsp_tim6_init(void){

    crm_periph_clock_enable(CRM_TMR6_PERIPH_CLOCK, TRUE);

    tmr_cnt_dir_set(TMR6, TMR_COUNT_UP);
    tmr_period_buffer_enable(TMR6, FALSE);
    tmr_primary_mode_select(TMR6, TMR_PRIMARY_SEL_RESET);

    tmr_counter_enable(TMR6, TRUE);
    tmr_base_init(TMR6, 1000-1, 240-1); 

    nvic_irq_enable(TMR6_GLOBAL_IRQn, 0, 0);

    tmr_interrupt_enable(TMR6, TMR_OVF_INT, TRUE);

    pstEventTim6 = cbb_event_register( &TMR6->ists_bit,EVENT_32, 0);

}
INIT_PORT_BSP(bsp_tim6_init);

void TMR6_GLOBAL_IRQHandler(void){

    if(TMR6->ists_bit.ovfif == 1){

        // 定时器事件监控
        cbb_event_monitor(pstEventTim6);

        TMR6->ists_bit.ovfif = 0;

    }
}
